#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 10;
int n;
int prices[N];
int main()
{
    cin >> n;
    if (n == 0) cout << n << endl;
    for (int i = 0; i < n; i++)
    {
        cin >> prices[i];
    }

    int f = 0, g = 0;
    f = -prices[0];
    for (int i = 1; i < n; i++)
    {
        int newf = max(f, g - prices[i]);
        int newg = max(g, f + prices[i]);
        f = newf, g = newg;
    }
    cout << g << endl;
    return 0;
}